package com.fbb.test;



import com.fbb.tet.R;

import android.app.TabActivity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
/**
 * 获取Android手机当前的网络接入点
 * @author fbb
 *
 */
public class GetVpnTypeActivity extends TabActivity{
    public TabHost th;
    public static GetVpnTypeActivity mainUI;
    public RadioButton bt02;
    public GetVpnTypeActivity()
    {
    	mainUI=this;
    }
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.setContentView(R.layout.maintabs);
		
//		getVpnType_1();
		getVpnType_2();
		
	}
	private void getVpnType_1() {
		ContentResolver contentResolver =this.getContentResolver();
		final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
        Cursor cursor = contentResolver.query(PREFERRED_APN_URI, new String[]{"_id", "apn", "type"},null, null, null );
        cursor.moveToFirst();
        if (cursor.isAfterLast()){
        }
        long id = cursor.getLong(0);
        String apn = cursor.getString(1);
        String type = cursor.getString(2);
        Log.d("fbb", "fbb  id:"+id+"  apn:"+apn+"  type:"+type);
	}
	private void getVpnType_2() {
		ConnectivityManager conManager = 
 			   (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
 			  NetworkInfo ni = conManager.getActiveNetworkInfo(); 
 			//获取网络接入点，中国移动:cmwap和cmnet; 中国电信ctwap，ctnet
 			String apn = ni.getExtraInfo();  
 			String typeName = ni.getTypeName();//moble\WIFI\
 			Log.d("fbb", "fbb  apn:"+apn);

			Intent intent = new Intent(
				//Settings.ACTION_LOCATION_SOURCE_SETTINGS);
				Settings.ACTION_APN_SETTINGS);
				//Settings.ACTION_WIRELESS_SETTINGS);
//				Settings.ACTION_WIFI_SETTINGS);
			startActivity(intent);
 	}

}
